package com.zzg.srb.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zzg.srb.core.entity.pojo.BorrowerAttach;
import com.zzg.srb.core.entity.vo.BorrowerAttachVo;
import com.zzg.srb.core.mapper.BorrowerAttachMapper;
import com.zzg.srb.core.service.BorrowerAttachService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 借款人上传资源表 服务实现类
 * </p>
 *
 * @author zhengzg
 * @since 2022-05-27
 */
@Service
public class BorrowerAttachServiceImpl extends ServiceImpl<BorrowerAttachMapper, BorrowerAttach> implements BorrowerAttachService {

    @Override
    public List<BorrowerAttachVo> selectBorrowerAttachVoList(Long borrowerId) {
        LambdaQueryWrapper<BorrowerAttach> borrowerAttachLambdaQueryWrapper = new LambdaQueryWrapper<>();
        borrowerAttachLambdaQueryWrapper.eq(BorrowerAttach::getBorrowerId,borrowerId);

        List<BorrowerAttach> borrowerAttaches = baseMapper.selectList(borrowerAttachLambdaQueryWrapper);

        ArrayList<BorrowerAttachVo> borrowerAttachVos = new ArrayList<>();

        borrowerAttaches.forEach(borrowerAttach -> {
            BorrowerAttachVo borrowerAttachVo = new BorrowerAttachVo();
            borrowerAttachVo.setImageType(borrowerAttach.getImageType());
            borrowerAttachVo.setImageUrl(borrowerAttach.getImageUrl());
            borrowerAttachVos.add(borrowerAttachVo);
        });

        return borrowerAttachVos;
    }
}
